//
//  ILGMRCTest.m
//  ILGDemo
//
//  Created by happy on 2020/2/18.
//  Copyright © 2020 Happy. All rights reserved.
//

#import "ILGMRCTest.h"

typedef void(^ILGMRCTestBlockType)(void);


@interface ILGMRCTest ()
@property (nonatomic, copy) ILGMRCTestBlock block;
@end

@implementation ILGMRCTest
{
    ILGMRCTestBlockType _block;
}

- (void)performTestMethod
{
    [self testingCodeOne];
}

- (void)dealloc {
    [super dealloc];
    
    NSLog(@"%s", __func__);
}

- (void)callWithBlock:(void(^)(void))completion {
    NSLog(@"completion = %@", completion);
    self.block = completion;
}

- (void)testBlock {
    NSLog(@"_block = %@", _block);
    self->_block();
}

- (ILGMRCTestBlock)mrcBlock {
    int age = 10;
    
    void(^returnBlock)(void) = [^{
        NSLog(@"mrcBlock called, age = %d", age);
    } copy];
    return returnBlock;
}

- (void)testingCodeOne
{
//    id __unsafe_unretained obj = self; //使用__block、__unsafe_unretained均可
//    self.block = ^{
//        NSLog(@"objc = %@", obj); //使用了obj，实际上会捕获self
//    };
//
//    self.block();
    
    int age = 0;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSLog(@"%d", age);
    });
}

@end
